package de.koller.million.render.obj;

import de.koller.oceanFramework.gl.util.ParticleTexture;
import de.koller.oceanFramework.tree.Sea3X;
import de.koller.oceanFramework.util.ColorIntUtil;

public class Sphere2D extends Sea3X {
	
	public static int TEXTURE_SIZE = 512;
	private final float sphereRadius = 250;
	private ParticleTexture texture;

	@Override
	protected void init() {
		super.init();
		
		texture = ParticleTexture.generate( TEXTURE_SIZE, TEXTURE_SIZE );
		texture.clear( 0x00000000 );
		for( int x = 0; x < TEXTURE_SIZE; x++ )
			for( int y = 0; y < TEXTURE_SIZE; y++ )
				texture.setPixel( pixel( x, y ), x, y );
		texture.flush();
	}

	private int pixel( int x, int y ) {
		double sx = x - TEXTURE_SIZE / 2d;
		double sy = y - TEXTURE_SIZE / 2d;

		double ds = Math.sqrt( sx*sx + sy*sy );
		double h = Math.sqrt( ds*ds + sphereRadius*sphereRadius );
		double f = 1 - (h / sphereRadius);
		
		if( f < 0 ) f = 0;
		int c = (int)(f * 255d);
		
		return ColorIntUtil.getIntColor( 0xff, c, c, c );
	}
	
	@Override
	protected void render( int elapsedTime ) {
		super.render( elapsedTime );
		
		texture.draw2D( 100, 100, 512, 512, 0 );
	}
	
}
